package com.inepex.inegraphics.impl.client;


/**
 * 
 * General purpose interface for long running progresses
 * 
 * @author Miklos Suveges / Inepex Ltd.
 *
 */
public interface IncrementallyUpdatable {
	
	public interface IncrementalUpdater{
		
		/**
		 * 25 fps - 40ms
		 */
		public static final long defaultUpdateTresholdMS = 40;
		
		/**
		 * The next update part's duration will be roughly around (or below) this value
		 * It may change between nextUpdatePart() calls. 
		 * Note that at least one upgrade part will be executed during each nextUpdatePart() call.
		 * @return [0;long.max]
		 */
		int getUpdatePartTresholdMS();
			
		
	}
	

	/**
	 * Initializes a new partial update progress, canceling not finished partial update if present.
	 * While the partial update is in progress a 'simple' update call should take no effect
	 * 
	 * @param updater
	 */
	void initUpdate(IncrementalUpdater updater);
	
	/**
	 * Call this method when the update may progress.
	 * starts updating the next part of the whole progress, if there is any
	 * true = in progress
	 * false = finish
	 * @return false if this method should not be called again 
	 */
	boolean nextUpdatePart();
	
	/**
	 * cancels the current (unfinished) progress
	 */
	void cancelUpdate();
	
	/**
	 * Returns the (roughly) estimated progress
	 * @return [0;1.0]
	 */
	double getProgress();

}
